﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Media.Imaging;

namespace Freshome.m.mds
{
    // Healthold type
    public class Healthold : Shortype<Rmt.Healthold>
    {
        public Healthold(Rmt.Healthold pm)
            : base(pm)
        { }
        public Healthold()
            : this(new Rmt.Healthold { Mid = default(short), Name = string.Empty })
        {
            _pm.Notes = string.Empty;
        }
        public string Name
        {
            get { return this._pm.Name; }
            set
            {
                value = value.Trim();
                if (value.Match(@"^[\S\s]{2,10}$") && this._pm.Name != value)
                {
                    this._pm.Name = value;
                    this.Updated = !Created;
                }
                OnPropertyChanged("Name");
            }
        }
        public override void Refresh(Rmt.Healthold pm)
        {
            this.Name = pm.Name;
            this.Notes = pm.Notes;
            this.Updated = false;
        }
        public bool IsValid
        {
            get
            {
                return _pm.Name.Match(@"^[\S\s]{2,10}$") && _pm.Notes.Match(@"^[\S\s]{0,50}$");
            }
        }
        private ObservableCollection<RightMate> _right = new ObservableCollection<RightMate>();
        public ObservableCollection<RightMate> Rights
        {
            get { return this._right; }
        }
        private ObservableCollection<WrongMate> _wrong = new ObservableCollection<WrongMate>();
        public ObservableCollection<WrongMate> Wrongs
        {
            get { return this._wrong; }
        }
    }
    // Rawithealth
    public abstract class Rawithealth : Shortype<Rmt.Rawithealth>
    {
        public Rawithealth(Rmt.Rawithealth pm)
            : base(pm)
        { }
        public short Jmx
        {
            get { return this._pm.Jmx; }
            set
            {
                if (this._pm.Jmx != value)
                {
                    this._pm.Jmx = value;
                    this.Updated = !Created;
                    OnPropertyChanged("Jmx");
                }
            }
        }
        public bool IsValid
        {
            get
            {
                return _pm.Notes.Match(@"^[\S\s]{0,50}$") && _pm.Jmx > default(short);
            }
        }
        public override void Refresh(Rmt.Rawithealth pm)
        {
            this.Notes = pm.Notes;
            this.Jmx = pm.Jmx;
            this.Raw.Hmx = pm.Hmx;
            this.Updated = false;
        }
    }
    public sealed class RightMate : Rawithealth
    {
        public RightMate()
            : this(new Rmt.Rawithealth { Mid = default(int), Taboo = false })
        {
            _pm.Jmx = default(short);
            _pm.Notes = string.Empty;
        }
        public RightMate(Rmt.Rawithealth pm)
            : base(pm)
        { }
    }
    public sealed class WrongMate : Rawithealth
    {
        public WrongMate()
            : this(new Rmt.Rawithealth { Mid = default(int), Taboo = true })
        {
            _pm.Jmx = default(short);
            _pm.Notes = string.Empty;
        }
        public WrongMate(Rmt.Rawithealth pm)
            : base(pm)
        { }
    }
}
